import torch.utils.data as data
from PIL import Image
import os

class kaggle(data.Dataset):
    def __init__(self, root, transform=None):
        super(kaggle, self).__init__()
        self.root = root
        self.transform = transform
        self.img_names = os.listdir(self.root)
        self.img_names.sort()

    def __len__(self):
        return len(self.img_names)

    def __getitem__(self, index):
        img_path = os.path.join(self.root, self.img_names[index])
        with open(img_path, 'rb') as f:
            img = Image.open(f)
            img = img.convert('RGB')
        if self.transform is not None:
            img = self.transform(img)
        return self.img_names[index], img
